import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	private static int MAX = 1000;
	
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true) {
			String str = br.readLine();
			if(str == null || str.trim().equals("")) {
				break;
			}
			
			Long n = Long.parseLong(str.trim());
			long[] memTable = new long[MAX];
			System.out.println(recurse(n, memTable));
		}
	}
	
	private static long recurse(long n, long[] memTable) {
		if(n == 0) {
			return 0;
		}
		
		long s = (n/2 < memTable.length ? (memTable[(int)n/2] != 0 ? memTable[(int)n/2] : recurse(n/2, memTable)) : recurse(n/2, memTable)) + 
				(n/3 < memTable.length ? (memTable[(int)n/3] != 0 ? memTable[(int)n/3] : recurse(n/3, memTable)) : recurse(n/3, memTable)) + 
				(n/4 < memTable.length ? (memTable[(int)n/4] != 0 ? memTable[(int)n/4] : recurse(n/4, memTable)) : recurse(n/4, memTable));
		long result = s > n ? s : n; 
		if(n < memTable.length) {
			memTable[(int)n] = result;
		}
		return result;
	}
}